package dancrawler.server.gamecmd;

import dancrawler.common.Misc;
import dancrawler.proto.cmd.CmdHandler;
import dancrawler.server.GameHandler;
import dancrawler.server.Player;
import dancrawler.server.PlayerChar;
import dancrawler.server.netMsg;

/**
 *
 */
public class CmdIncStat extends CmdHandler {

    private GameHandler gh;

    public CmdIncStat(GameHandler gh) {
        this.gh = gh;
    }

    @Override
    public void handleCmd(netMsg msg) {
        int s = Misc.bytesToShort(msg.getArgs()[0]);
        Player pl = gh.getPlayer(msg.getSender().getId());
        if (pl == null) {
            return;
        }
        PlayerChar pc = pl.getPc();
        if (pc.getUStats() > 0) {
            if (s == 1) {
                pc.modStrength(1);
            } else if (s == 2) {
                pc.setMaxHp(pc.getMaxHp() + 10);
            } else if (s == 3) {
                pc.setDef(pc.getDef() + 1);
            }
            pc.decUStats();
        }
    }

    @Override
    public int getId() {
        return 26;
    }

    @Override
    public CmdHandler getHandler() {
        return this;
    }
}
